# Maintainer: Jami Kettunen <jami.kettunen@protonmail.com>
# Mainline Linux kernel fork with patches for MediaTek MT6768 devices
# Kernel config based on: arch/arm64/configs/mt6768_defconfig
_flavor="postmarketos-mediatek-mt6768"
pkgname=linux-$_flavor
pkgver=6.1_rc5
pkgrel=2
_commit="d8741eb21ebe5b989e69e40a058cd2d593397ae2"
pkgdesc="Mainline Kernel fork for MT6768-based devices"
arch="aarch64"
_carch="arm64"
_config="config-$_flavor.$arch"
url="https://gitlab.com/mtk-mainline/mt6768/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
"
makedepends="
	android-tools
	bash
	bison
	findutils
	flex
	linux-headers
	openssl-dev
	perl
	postmarketos-installkernel
	xz
"

# Source
source="
	https://gitlab.com/mtk-mainline/mt6768/linux/-/archive/$_commit/linux-$_commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1))-$_flavor"\
		V=1
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release

	dtbodir="$builddir/$_outdir/arch/arm64/boot/dts/mediatek"
	mkdtboimg create "$pkgdir/boot/dtbo.img" \
		"$dtbodir/mt6769z-volla-mimameid-minimal-dtbo.dtb"
}

sha512sums="
20cd7ce324ff0a29a1ceaf0c69e77d619c0b21c924c0913214070308774cb88f1c803bef0da0a85d9bbca3797eadd7f63bb9bc6cf256350c658a8820c275c1e3  linux-d8741eb21ebe5b989e69e40a058cd2d593397ae2.tar.gz
6f533fbcbe220bcf167f5dac73812adde52e58461695076883f1d028f89c3d32fd52aa96823a4c17a96ea1cddfb9a8a0502153b5d99943df5b714067955d5f52  config-postmarketos-mediatek-mt6768.aarch64
"
